﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

using AttributeRouting;
using AttributeRouting.Web.Mvc;
using Newtonsoft.Json.Linq;
using PH.Model.Results;
using PH.Model.Standards;
using PH.Logic.Standards;
namespace PH.Web.Management.Areas.Standard.Controllers
{
    [RouteArea("Standard")]
    [RoutePrefix("Evaluation")]
    public class EvaluationApiController : ApiController
    {
        //[Route("GetEhaws")]
        //[HttpPost]
        //public JsonEntitySet<EHAWModel> GetEhaws(JObject request)
        //{
        //    string errinfo = "no data";
        //    try
        //    {
        //        EvaluationQuery sea = new EvaluationQuery();
        //        sea.PageIndex = request.Value<int>("pageIndex");
        //        sea.PageSize = request.Value<int>("pageSize");
        //        sea.GradeCode = request.Value<int>("gradeCode");
        //        sea.Sex = request.Value<byte>("sex");
        //        var result = EHAWLogic.Gets(sea);
        //        return new JsonEntitySet<EHAWModel>(result);
        //    }
        //    catch (Exception ex)
        //    {
        //        errinfo = ex.Message;
        //        Common.Logger.Error("", ex);
        //    }
        //    return new JsonEntitySet<EHAWModel>(null, errinfo, false);
        //}

        [Route("Gets")]
        [HttpPost]
        public JsonEntitySet<EvaluationModel> Gets(JObject request)
        {
            string errinfo = "no data";
            try
            {
                EvaluationQuery sea = new EvaluationQuery();
                sea.PageIndex = request.Value<int>("pageIndex");
                sea.PageSize = request.Value<int>("pageSize");
                sea.GradeCode = request.Value<int>("gradeCode");
                sea.Sex = request.Value<byte>("sex");
                sea.SubjectID = request.Value<int>("subjectID");
                sea.Additional = request.Value<bool?>("additional");
                var result =EvaluationStandardLogic.Gets(sea);
                return new JsonEntitySet<EvaluationModel>(result);
            }
            catch (Exception ex)
            {
                errinfo = ex.Message;
                Common.Logger.Error("", ex);
            }
            return new JsonEntitySet<EvaluationModel>(null, errinfo, false);
        }

        [Route("GetEBMI")]
        [HttpPost]
        public JsonEntitySet<EBMIModel> GetEBMI(JObject request)
        {
            string errinfo = "no data";
            try
            {
                EvaluationQuery sea = new EvaluationQuery();
                sea.PageIndex = request.Value<int>("pageIndex");
                sea.PageSize = request.Value<int>("pageSize");
                sea.GradeCode = request.Value<int>("gradeCode");
                var result = EBMILogic.Gets(sea);
                return new JsonEntitySet<EBMIModel>(result);
            }
            catch (Exception ex)
            {
                errinfo = ex.Message;
                Common.Logger.Error("", ex);
            }
            return new JsonEntitySet<EBMIModel>(null, errinfo, false);
        }
    }
}
